﻿using System.Windows.Input;

namespace RobotPerCeption.ViewMod
{
    public class RobotConnectViewModel : ICommand


    {
        /// <summary>
        /// Event handler
        /// 事件出发时先调用CanExecute（），然后调用
        /// </summary>
        public event EventHandler CanExecuteChanged;
        /// <summary>
        /// Execute action.
        /// </summary>
        public Action<object> DoExecute { get; set; }

        /// <summary>
        /// Canexecute method.
        /// </summary>
        public Func<object, bool> DoCanExecute { get; set; } = new Func<object, bool>(obj => true);

        /// <summary>
        /// Can execute.
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public bool CanExecute(object parameter)
        {
            //初始化时会调用一次
            return DoCanExecute?.Invoke(parameter) == true;
        }
        /// <summary>
        /// Excute.
        /// </summary>
        /// <param name="parameter"></param>
        public void Execute(object parameter)
        {
            //实例化委托。
            DoExecute?.Invoke(parameter);
        }

        /// <summary>
        /// 执行委托，调用CanExecute。
        /// </summary>
        public void DoCanExecuteChanged()
        {
            CanExecuteChanged?.Invoke(this, EventArgs.Empty);
        }


    }
}
